class Exploitdb < Formula
  desc "Database of public exploits and corresponding vulnerable software"
  homepage "https://www.exploit-db.com/"
  url "https://gitlab.com/exploit-database/exploitdb.git",
      tag:      "2024-01-24",
      revision: "967f9d17d60b6bde14947d2f6f2d8e48035b4bee"
  license "GPL-2.0-or-later"
  head "https://gitlab.com/exploit-database/exploitdb.git", branch: "main"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_sonoma:   "393b42a9b1130abbed11f316a73414385a2e65825baa1b095945e63cd0d71c0f"
    sha256 cellar: :any_skip_relocation, arm64_ventura:  "98b075a63e3391ef54aa38156f8844cd126f185bec3e11ba871e10f875089232"
    sha256 cellar: :any_skip_relocation, arm64_monterey: "9d52e0bd313ddc8d578e2fcc86155140a8ed442e5bc60fd2cdb8874158c4fd60"
    sha256 cellar: :any_skip_relocation, sonoma:         "43285528e211648cce88cddb53ce3e885dcc267176968ac97a1e6949b9a8ab9c"
    sha256 cellar: :any_skip_relocation, ventura:        "2e4a7aba779ea1ba621d4ea709c64898b30d84c38b3e4a2940bce8bd25365129"
    sha256 cellar: :any_skip_relocation, monterey:       "1f06fd683946aec01bc6d941c46701ee5160fcac3d340f9270597b8d9afede77"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "0a011bdc3f1ae87cd52489d5aecdce5899819e15e2059d75f6e0d10a9310739b"
  end

  def install
    inreplace "searchsploit",
              "rc_file=\"\"", "rc_file=\"#{etc}/searchsploit_rc\""

    optpath = opt_share/"exploitdb"
    inreplace ".searchsploit_rc" do |s|
      s.gsub! "\"/opt/exploitdb\"", optpath
      s.gsub! "\"/opt/exploitdb-papers\"", "#{optpath}-papers"
    end

    bin.install "searchsploit"
    etc.install ".searchsploit_rc" => "searchsploit_rc"

    pkgshare.install %w[.git exploits files_exploits.csv files_shellcodes.csv
                        shellcodes]
  end

  test do
    system "#{bin}/searchsploit", "sendpage"
  end
end
